home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d1
/
clipasc.arc
/
CLIPASC.DOC
< prev
next >
Wrap
Text File
|
1987-03-17
|
10KB
|
330 lines
CLIPASC
ASCII File Access From Clipper
Version 1.1
Written by Ben Cohen
CLIPASC is a set of User Defined functions, programmed in Assembler
which allow a program written in Clipper to access and manipulate
information contained in flat ASCII files.
Files in this package:
CLIPASC.ASM Source code for CLIPASC
ASCSCAN.MAC Macro definitions for CLIPASC
CLIPASC.OBJ Compiled version of CLIPASC
CLIPASC.DOC This document
Since CLIPASC was written as part of a project for Irving Trust
Company, I am unable and unwilling to request any payment for this
function package. However, I appreciate it if people would let me know
about any problems that you encounter while using CLIPASC. In addition,
I would like any suggestions for upgrades to be made to CLIPASC. While
writing it, I made sure that it had all of the functionality that I
required, but there may be more lurking out there that is still needed.
Please address any correspondence to:
Ben Cohen
12 Britton St.
Jersey City, NJ 07306
Re: CLIPASC
I make no promises that I will fix all errors that are presented,
although I will try. In addition, I make no claims that any suggestions
will be implemented. My time is limited and this was written out of
necessity. And, lastly, both CLIPASC and myself are not in any way,
shape, or form responsible for any damage that may result from the use
of CLIPASC. Use this at your own risk.
And, now for the good stuff:
Using CLIPASC
CLIPASC consists of 8 functions that all work together to read and
write files, although they work at different levels.
OPENASC():
OPENASC will open a file in a specified read/write mode. It
returns the file handle that was returned by DOS which is used for
all future file operations.
The syntax for OPENASC is:
OPENASC(name,mode)
Where: name - fully expanded file name and extension
mode - file mode to use. Possible modes are:
r - file is read only. Positioned at
beginning of file.
w - file is write only. If file exists, it
is truncated. Otherwise, it is created.
r+ - file is read only. Positioned at end
of file.
w+ - file is write only. Positioned at end of
file, if file exists. Otherwise, file is
created.
rw - file is read/write. Positioned at
beginning of file, if file exists.
Otherwise, file is created.
rw+ - file is read/write. Positioned at end of
file, if file exists. Otherwise, file is
created.
Return values:
-1 = indicates error. Use ASCRETCD() to get error code.
Any other returned value is the file handle. This number must
be retained for all future file accesses.
CLOSEASC():
CLOSEASC will close a previously opened file so that it is no
longer able to be used. This will also release the file handle that
was associated with the file so it might be reused by a different
file.
The syntax for CLOSEASC is:
CLOSEASC(handle)
Where: handle - file handle that was returned from OPENASC.
Return values:
0 = no error. File closed ok.
-1 = error. Use ASCRETCD() to get error code.
LINEIN():
LINEIN reads a sequence of characters from a specified file up
through and past the first CR-LF sequence encountered in the file.
This string is then returned to Clipper and your program.
The syntax for LINEIN is:
LINEIN(handle)
Where: handle - file handle that was returned from OPENASC.
Returns:
null string = indicates possible error. Check ASCRETCD() to be
certain. If ASCRETCD() = 0, no error occured, just an
empty line. Also, if ASCRETCD() = -1, EOF has been
reached.
otherwise, next CR-LF delimited line is returned.
Note:
Lines from the file must be no greater than 512 bytes or else you
will receive an error and a possible loss of data. Since most data
that is worked with has line lengths below about 150, this was
not deemed to be a very bad problem.
LINEOUT():
LINEOUT will write a string to a file after appending a CR-LF
to the end of the string so that it will appear as a regular 'line'.
The syntax for LINEOUT is:
LINEOUT(handle,string)
Where: handle - file handle that was returned from OPENASC.
string - a string variable from Clipper. This string
must be no greater than 512 bytes or else it
will not be written.
Returns:
0 = no error. Line written
-1 = indicates error. Use ASCRETCD() to get error code.
Designers Note:
I'd considered adding support so that CLIPASC could write out
the full string and then just write out the CRLF when it was done.
I decided against this method for ease and consistency. If there
is enough demand for this, I may again consider implementing it.
However, how many people really use ASCII files greater than 512
bytes wide?
CHARIN():
CHARIN will read a specified number of characters from a file.
This read will be performed with no CR-LF translation whatsoever, so
you will get the bytes directly from the file.
The syntax for CHARIN is:
CHARIN(handle[,count])
Where: handle - file handle that was returned from OPENASC.
count - optional count of characters to read from file.
If not specified, count defaults to 1 character.
Count must be 512 or less.
Returns:
null string = indicates error. Use ASCRETCD() to get error code.
If ASCRETCD() = -1, EOF has been reached.
Otherwise, the characters read from handle are returnde.
CHAROUT():
CHAROUT will write a string out to the specified handle without
appending a trailing CR-LF. CHAROUT can also be used for file
truncation.
The syntax for CHAROUT is:
CHAROUT(handle[,string])
Where: handle - file handle that was returned from OPENASC.
string - character string to be written to the file. If
string is null, the file will be truncated at
the current file pointer.
Returns:
0 = no error. String written.
-1 = error. Use ASCRETCD() to get error code.
ASCLSEEK():
ASCLSEEK implements the DOS LSEEK function which allows change
of position within a file.
The syntax for ASCLSEEK is:
ASCLSEEK(handle[,[method][,offset]])
Where: handle - file handle that was returned from OPENASC.
method - corresponds to the three types of movement for
LSEEK: from beginning of file, from end of file,
and from current position in file. Possible
methods are:
b|B - offset is from beginning of file.
c|C - offset is from current position
in file.
e|E - offset is from end of file.
If method is not specified, it defaults to 'c',
which is offset from current position in file.
offset - optional distance to move within file. Offset
is invalid if method is 'e' (from end of file).
If not specified, offset defaults to 0, meaning
no offset.
Return values:
-1 = error. Use ASCRETCD() to get error code.
Otherwise, returned value corresponds to the pointer position
in the file.
ASCRETCD():
ASCRETCD will give you the return code of the last function from
the CLIPASC function package that was called, with the exception of
ASCRETCD itself. ASCRETCD can be called multiple times and will
return the same value each time until another function from CLIPASC
is called.
The syntax for ASCRETCD is:
ASCRETCD()
Return values:
0 = indicates that last operation was successful.
Otherwise, value is from the following selections:
4096 - 8191 = DOS error codes offset by 4096. Therefore, DOS
error code 1 is equivalent to 4097. The more likely
return codes are:
4098 = File not found
4099 = Path not found
4100 = No handles left
4102 = Invalid handle
8192 = Invalid number of parameters passed to the function.
8200 - 8300 = Error in one of the passed parameters. The offset
from 8200 indicates which parameter was in error. For
example, 8201 indicates that the first parameter was in
error.
8301 = Invalid mode used when opening a file.
8401 = Invalid method used for ASCLSEEK on a file.
CLIPASC Examples
The following code fragment will open two files and copy one file to
the other with no error checking other than EOF. The input and output
file names are in the variables FILE1 and FILE2 respectively.
handle_1 = openasc(file1,'r') && open for reading
handle_2 = openasc(file2,'w') && create for writing
do while .T.
input = linein(handle_1) && read a line
if ascretcd() = -1 && EOF?
exit
endif
x = lineout(handle_2) && write it out and throw away
&& the return value
enddo
x = closeasc(handle_1) && close one file
x = closeasc(handle_2) && close the other
The following will read in the input file one character at a time,
searching for 0xFE. When 0xFE is found, the next 10 bytes will be
skipped over. All other input information will be written to an output
file. The input and output file handles are in handle_i and handle_o
respectively:
do while .T.
input = charin(handle_i) && default to one character read
if ascretcd() = -1 && EOF?
exit
endif
if input = chr(254) && 0xFE?
x = asclseek(handle_i,'c',10)
else
x = charout(handle_o,input)
endif
enddo
Change History
Version 1.1 - minor fixes from original (v1.0)
Rewrite of return sections so that ES and BP restored before
calling _retxx functions. This may have caused some problems, but
none that exhibited themselves.
Change combine class of code segment to 'PROG'. This forces the
linker to include it in before any of the library modules get
linked in. This prevents the code from getting overwritten at
runtime, which was happening with a combine class of 'CODE'.